package com.jcl.recruit.console.mapper;

import com.jcl.recruit.console.model.ConsoleCorpInfo;
import com.jcl.recruit.console.mapper.provider.ConsoleCorpInfoProvider;
import com.jcl.recruit.console.vo.ConsoleCorpPageCondition;
import com.jcl.recruit.mapper.SqlMapper;
import com.jcl.recruit.mapper.provider.SqlProvider;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @ClassName ConsoleCorpInfoMapper
 * @Author yyliu
 * @Date 2018/12/13 16:45
 * @Version 1.0
 **/
public interface ConsoleCorpInfoMapper extends SqlMapper {

    String TABLE_NAME = "t_corp_info";

    String SQL_ORDER_DESC = " order by id desc ";

    @Select({
            SQL_QUERY,
            SQL_ORDER_DESC
    })
    List<ConsoleCorpInfo> findList();

    @Select({
            QUERY_SCRIPT_START,
            SQL_QUERY,
            QUERY_WHERE_START,
            "<if test='null!=keyword'>",
            " full_name like '%${keyword}%' ",
            IF_END,
            QUERY_WHERE_END,
            SQL_ORDER_DESC,
            QUERY_SCRIPT_END
    })
    List<ConsoleCorpInfo> pageList(ConsoleCorpPageCondition condition);

    @Select({
            SQL_QUERY,
            SQL_ORDER_DESC
    })
    List<Map<String, Object>> getCountList();

    @Select({
            SQL_QUERY_ID
    })
    ConsoleCorpInfo findOne(@Param("id") Integer id);

    @Select({
            SQL_QUERY_CODE
    })
    ConsoleCorpInfo findOneByCode(@Param("code") String code);

    @InsertProvider(type = ConsoleCorpInfoProvider.class, method = SqlProvider.SQL_METHOD_INSERT)
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(ConsoleCorpInfo entity);

    @UpdateProvider(type = ConsoleCorpInfoProvider.class, method = SqlProvider.SQL_METHOD_UPDATE)
    int updateByPrimaryKey(ConsoleCorpInfo entity);

    @Delete({
            SQL_DELETE_ID
    })
    int deleteById(@Param("id") Integer id);

    String SQL_QUERY = "select * from " + TABLE_NAME;
    String SQL_QUERY_ID = "select * from " + TABLE_NAME + " where id = #{id}";
    String SQL_QUERY_CODE = "select * from " + TABLE_NAME + " where code = #{code}";
    String SQL_DELETE_ID = "delete from " + TABLE_NAME + " where id = #{id}";
    String SQL_COUNT_ENTITY = "select count(*) from " + TABLE_NAME;
}
